import VueRouter from 'vue-router'
 
import ChatHome from '../view/pages/chatHome/index.vue'
import Login from '../view/pages/chatHome/Login.vue' 
import Cookies from 'js-cookie';
const router = new VueRouter({
    routes: [
      {
        path: '/',
        redirect: '/ChatHome',
      },
      {
        path: '/Login',
        name: 'Login',
        component: Login,
      },
      {
        path: '/ChatHome',
        name: 'ChatHome',
        component: ChatHome,
      },
    ],
  });
  
  // 添加全局导航守卫
  router.beforeEach((to, from, next) => {
    let username = sessionStorage.getItem('username')
    let _this = this;
    if(to.path === '/Login') {
        next();
    }else if(username === null) {
        alert('请先登录');
        next('/Login');
    }
    else {
        next();
    }
  });
  
export default router;